{extend name="base" /}
{block name="body"}

<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-btn-group">
            <a class="layui-btn" data-width="830px" data-height="800px" id="add"><i class="fa fa-plus-circle"></i> 添加</a>
            <a id="delAll" class="layui-btn" data-width="830px" data-height="800px" style="margin-left: 20px"><i class="fa fa-minus-circle"></i> 删除</a>
            <input id="addurl" value="/admin/agency/agency_add?isedit=0" hidden="hidden">
            <input id="oriaddurl" value="/admin/agency/agency_add?isedit=0" hidden="hidden">
            <input id="editurl" value="/admin/agency/agency_add?isedit=1" hidden="hidden">
        </div>
    </div>

    <table id="tableList" lay-filter="tableList"></table>
    <!-- 表格操作列 -->
    <script type="text/html" id="tableTBTrack">
        <a id="edit" data-id="{{d.id}}" class="layui-btn layui-btn-sm" data-width="830px" data-height="800px">修改</a>
        <a href="{:url('admin/agency/agency_del')}?id={{d.id}}" class="layui-btn  layui-btn-sm layui-btn-danger ajax-delete">删除</a>
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="sort_order">
        <input type="text" value="get_ad({{d.id}},'desc')" autocomplete="off" class="layui-input" disabled>
    </script>

</div>

{/block}
{block name="js"}

<script>
    layui.use(['layer', 'form', 'table', 'util', 'dropdown'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var dropdown = layui.dropdown;

        // 渲染回访表格
        var insTb = table.render({
            elem: '#tableList',
            url: "{:url('admin/agency/agency_json')}",
            page: true,
            limit:10,
            limits:[15,30,45,60,75,90],
            cellMinWidth: 100,
            size:'lg',even:true,
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {type:'numbers',title:'#'},
                {field: 'code', title: '机构编码'},
                {field: 'name', title: '机构名称'},
                {field: 'deposit', title: '保证金金额'},
                {field: 'effect_time', title: '生效日期'},
                {field: 'lose_time', title: '失效日期'},
                {field: 'insurenum', title: '保单数量'},
                {field: 'commision', title: '每单抽成'},
                {field: 'left_deposit', title: '剩余保证金'},
                {align: 'center', toolbar: '#tableTBTrack', title: '操作', width: 150}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
        });
    });

    $('#delAll').click(function(){
        var data = table.cache.tableList;
        var ids = [];

        for(let i = 0;i<data.length;i++){
            if(data[i]['LAY_CHECKED'] == true){
                ids.push(data[i]['id']);
            }
        }

        layer.confirm('确定要删除吗', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url:'agency_del',
                data:{'id':ids},
                method:'post',
                success:function(res){
                    layer.open({
                        content: res.msg //这里content是一个普通的String
                    });
                    window.location.reload();
                }
            });
        });
    })

</script>
{/block}